package com.xinyi.shicihui.pojo.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author xinyi
 * @desc
 * @date 2022/1/27
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Result<T> {
    private Integer code;
    private String message;
    private T data;

    public static <T> Result<T> success() {
        return success(null);
    }

    public static <T> Result<T> success(T data) {
        ResultCode rce = ResultCode.OK;
        return new Result<>(rce.getCode(), rce.getMessage(), data);
    }

    public static <T> Result<T> failed(ResultCode code) {
        return new Result<>(code.getCode(), code.getMessage(), null);
    }

}
